# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    def isSymmetric(self, root):
        """
        :type root: TreeNode
        :rtype: bool
        """
        def traverse(left, right):
            full = (1 if left else 0) + (1 if right else 0)
            if full==0: return True
            elif full==1: return False
            else:
                if left.val!=right.val: return False
                else: return traverse(left.left, right.right) and traverse(left.right, right.left)
        return traverse(root, root)
            